#ifdef _MSC_VER
/*
 * we do not want the warnings about the old deprecated and unsecure CRT functions
 * since these examples can be compiled under *nix as well
 */
#define _CRT_SECURE_NO_WARNINGS
#endif


#include "stdafx.h"
#include "JHComm.h"
#include "JHZk.h"


int main()
{
	HANDLE hdl;
	JHINFO_SERIALPORT JHInfo_serialport;
	int ret;

	/* Create instance */
	JHCreateInst(&hdl, 0);
	if (NULL == hdl)
	{
		printf("\nFailure to create instance!\n");
		return -1;
	}

	/* Communication mode and parameters setting */
	JHInfo_serialport.size = sizeof(JHINFO_SERIALPORT);
	memcpy(JHInfo_serialport.serialport, "COM1", 5);
	JHInfo_serialport.baudrate = 115200;
	JHInfo_serialport.databits = 8;
	JHInfo_serialport.parity = 0;
	JHInfo_serialport.stopbits = 0;
	JHInfo_serialport.reserved = 0;
	JHInfo_serialport.timeout = 5000;
	JHMountTransportLayer(hdl, &JHTransportlayer_serialport, (const void *)(&JHInfo_serialport));

	/* Set default ledmodule operation*/
	JHLEDMODULE JHLedModule;
	JHLedModule.lmScanDirection = 0;
	JHLedModule.lmColor = 0;
	JHLedModule.lmScan = 4;
	JHLedModule.lmOSR = 4;
	JHLedModule.lmOSC = 8;
	JHLedModule.lmRowDecode = 0;
	JHLedModule.lmPolar = 4;
	JHLedModule.lmClockPhase = 0;
	JHLedModule.lmLatchPhase = 0;
	JHLedModule.lmData = 0;
	JHLedModule.lmReserve[0] = 0;
	JHLedModule.lmReserve[1] = 0;
	JHLedModule.lmReserve[2] = 0;
	JHLedModule.lmReserve[3] = 0;
	JHLedModule.lmReserve[4] = 0;
	JHLedModule.lmReserve[5] = 0;
	JHLedModule.lmTrackMode = 1;
	JHLedModule.lmTrackSize = 0;

	unsigned char pTrack[512] = {0};

	JHZRESULT res = JHSetDefLedMod(hdl, &JHLedModule, pTrack);
	if (JR_OK == res)
	{
		printf("\nSuccessed in setting default ledmodule!\n");
		ret = 0;
	}
	else
	{
		printf("\nFailure to set default ledmodule!\n");
		ret = -1;
	}

	/* Delete instance */
	JHDeleteInst(hdl);

	Sleep(2000);

	return ret;
}
